package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(name = "loginServlet_1",urlPatterns = {"/loginServlet_1"})
public class LoginServlet_1 extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String name = request.getParameter("user");
        String password = request.getParameter("pwd");
        if (name == null || name.length() == 0 || !name.equals("zhangsan")) {
            response.sendRedirect("login_1.jsp");
        } else if (password == null || password.length() == 0 || !password.equals("123")) {
            response.sendRedirect("login_1.jsp");
        } else if (name.length() > 0 && password.length() > 0) {
            if (name.equals("zhangsan") && password.equals("123")) {
                RequestDispatcher dis = request.getRequestDispatcher("loginSuccess_1.jsp");
                dis.forward(request, response);
            } else {
                response.sendRedirect("login_1.jsp");
            }
        }
    }
}
